package com.hxzy.shop.common.dto.auth;

import com.hxzy.shop.common.dto.auth.req.AddAccountReq;
import com.hxzy.shop.common.dto.auth.req.AddRoleReq;
import com.hxzy.shop.common.dto.auth.resp.AccountDetailResp;
import com.hxzy.shop.common.dto.auth.resp.RoleDetailResp;
import com.hxzy.shop.entity.AdminAccount;
import com.hxzy.shop.entity.AdminRole;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @Author wy
 * @Description mapStruct转换对象，这个方案比BeanUtils.copyProperties快N倍
 * @Date 2023/5/12 15:24
 * @Version 1.0
 */
@Mapper
public interface AuthMapStructConvert {

    /**
     * 生成代理实现对象
     */
    AuthMapStructConvert  INSTANCE= Mappers.getMapper(AuthMapStructConvert.class);


    /**
     * 把AdminRole里面的属性复制到RoleDetailResp中有变量值里面
     * @param source
     * @return
     */
    @Mappings(
        value = {@Mapping(target = "roleId",source = "id")}
    )
    RoleDetailResp  toResp(AdminRole source);


    AdminRole toEntity(AddRoleReq req);

    AdminAccount toEntity(AddAccountReq req);

}
